import { GCellRenderer } from "../../../../com/mui/controls/GCellRenderer";
import { GTextFormat } from "../../../common/GTextFormat";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { BaseItem } from "../common/BaseItem";
import { ObjCreate } from "../common/ObjCreate";
import { Language } from "../../../../extend/language/Language";
import { SMarketItem } from "../../../../Message/Game/SMarketItem";
import { EMarketRecordType } from "../../../../Message/Game/EMarketRecordType";
import { EPrictUnit } from "../../../../Message/Public/EPrictUnit";
import { ItemData } from "../../resource/info/ItemData";
import { StringHelper } from "../../../../com/gengine/utils/StringHelper";
import { JSON } from "../../../../com/mui/serialization/json/JSON";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { ECategory } from "../../../../Message/Public/ECategory";
import { MoneyUtil } from "../common/util/MoneyUtil";
import { ColorConfig } from "../../resource/ColorConfig";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { EMarketOperation } from "../../../../Message/Game/EMarketOperation";
import { GButton } from "../../../../com/mui/controls/GButton";
import { _marketId } from "../../../../this/_marketId";
import { _EMarketOperationCancelSeekBuy } from "../../../../EMarketOperation/_EMarketOperationCancelSeekBuy";
import { _EMarketOperationCancelSell } from "../../../../EMarketOperation/_EMarketOperationCancelSell";
type int = number;
//class MarketMyGoodsRenderer
    
    export  class MarketMyGoodsRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            return;
        }

        protected /* override */ configUI(): void
        {
            this._blueTf = new GTextFormat("", 12, 11661311);
            this._coinImg = GlobalClass.getBitmap(ImagesConst.Market_Coin);
            this._coinImg.x = 10;
            this._coinImg.y = 10;
            this._coinImg.visible = false;
            addChild(this._coinImg);
            this._goldImg = GlobalClass.getBitmap(ImagesConst.Market_Gold);
            this._goldImg.x = 10;
            this._goldImg.y = 10;
            this._goldImg.visible = false;
            addChild(this._goldImg);
            this._item = new BaseItem();
            this._item.setSize(32, 32);
            this._item.move(5, 10);
            addChild(this._item);
            this._nameTxt = this.createTextfield(40, 20, 100, 20, "", this._blueTf);
            this._priceTxt = this.createTextfield(155, 20, 50, 20, "", this._blueTf);
            this._coinIcon = GlobalClass.getBitmap(ImagesConst.Tongqian);
            this._coinIcon.x = 130;
            this._coinIcon.y = 20;
            addChild(this._coinIcon);
            this._goldIcon = GlobalClass.getBitmap(ImagesConst.Yuanbao);
            this._goldIcon.x = 130;
            this._goldIcon.y = 20;
            addChild(this._goldIcon);
            var loc1=ObjCreate.createBg(10, 50, 255, 2, this, ImagesConst.SplitLine);
            this._cancelBtn = ObjCreate.createGButton(Language.getString(31035), 200, 15, 70, 25, this);
            this._cancelBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onCancelBtnClickHandler);
            this._cancelBtn.drawNow();
            return;
        }

        /* internal  */createTextfield(arg1: int, arg2: int, arg3: int, arg4: int, arg5: string, arg6: Object /* flash.text.TextFormat */): Object /* flash.text.TextField */
        {
            var loc1;
            (loc1 = new Object /* flash.text.TextField */()).x = arg1;
            loc1.y = arg2;
            loc1.width = arg3;
            loc1.height = arg4;
            loc1.text = arg5;
            loc1.selectable = false;
            loc1.mouseEnabled = false;
            loc1.setTextFormat(arg6);
            addChild(loc1);
            return loc1;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc3=null;
            var loc4=null;
            var loc5=null;
            var loc6=null;
            var loc7=0;
            var loc8=null;
            var loc9=null;
            super.data = arg1;
            this._item.itemData = null;
            this._coinImg.visible = false;
            this._goldImg.visible = false;
            this._sMarketItem = arg1 as SMarketItem;
            if (this._sMarketItem && this._sMarketItem.recordType == EMarketRecordType._EMarketRecordTypeSell) 
            {
                this._cancelBtn.label = Language.getString(31035);
            }
            else if (this._sMarketItem && this._sMarketItem.recordType == EMarketRecordType._EMarketRecordTypeSeekBuy) 
            {
                this._cancelBtn.label = Language.getString(31134);
            }
            this._marketId = this._sMarketItem.marketId;
            var loc1=this._sMarketItem.code;
            if (loc1 != EPrictUnit._EPriceUnitCoin) 
            {
                if (loc1 != EPrictUnit._EPriceUnitGold) 
                {
                    loc3 = new ItemData(loc1);
                    this._item.itemData = loc3;
                    this._sMarketItem.itemExtend = StringHelper.trim(this._sMarketItem.itemExtend);
                    loc4 = "";
                    loc5 = "";
                    loc6 = "";
                    loc7 = 0;
                    if (!(this._sMarketItem.itemExtend == "") && !(this._sMarketItem.itemExtend == null) && !(this._sMarketItem.itemExtend == "null")) 
                    {
                        loc8 = JSON.deserialize(this._sMarketItem.itemExtend);
                        this._item.itemData.setItemExInfo(loc8);
                        this._item.itemData = this._item.itemData;
                        if (loc8.prefix) 
                        {
                            loc7 = loc8.prefix;
                        }
                        if ((loc9 = GameDefConfig.instance.getEPrefixx(loc7, loc3.type)) && loc3.itemInfo.item.category == ECategory._ECategoryEquip) 
                        {
                            loc5 = loc9.name + Language.getString(31038);
                        }
                        if (!(loc8.strengthen == undefined) && !(loc8.strengthen == 0)) 
                        {
                            loc6 = "+" + loc8.strengthen;
                        }
                    }
                    loc4 = loc5 + loc3.itemInfo.item.name + loc6;
                    this._item.amount = this._sMarketItem.amount;
                    this._nameTxt.text = loc4;
                }
                else 
                {
                    this._goldImg.visible = true;
                    this._nameTxt.text = MoneyUtil.getFormatInt(this._sMarketItem.amount) + Language.getString(31037);
                }
            }
            else 
            {
                this._coinImg.visible = true;
                this._nameTxt.text = MoneyUtil.getFormatInt(this._sMarketItem.amount) + Language.getString(31036);
            }
            this._priceTxt.text = MoneyUtil.getFormatInt(this._sMarketItem.sellPrice) + "";
            var loc2=ColorConfig.instance.getItemColor(this._sMarketItem.color).intColor;
            this._nameTxt.setTextFormat(new GTextFormat("", 12, loc2));
            this._priceTxt.setTextFormat(this._blueTf);
            if (this._sMarketItem.sellUnit != EPrictUnit._EPriceUnitCoin) 
            {
                if (this._sMarketItem.sellUnit == EPrictUnit._EPriceUnitGold) 
                {
                    this._coinIcon.visible = false;
                    this._goldIcon.visible = true;
                }
            }
            else 
            {
                this._coinIcon.visible = true;
                this._goldIcon.visible = false;
            }
            return;
        }

        /* internal  */onCancelBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._cancelBtn.label != Language.getString(31035)) 
            {
                if (this._cancelBtn.label == Language.getString(31134)) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.MarketCancelSell, {"marketId": _marketId, "operation": _EMarketOperationCancelSeekBuy}));
                }
            }
            else 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.MarketCancelSell, {"marketId": _marketId, "operation": _EMarketOperationCancelSell}));
            }
            return;
        }

        /* internal */ /* var */_blueTf: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_coinIcon: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_goldIcon: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_coinImg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_goldImg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_item: BaseItem;

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_priceTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_marketId: number;

        /* internal */ /* var */_sMarketItem: SMarketItem;

        /* internal */ /* var */_cancelBtn: GButton;
    }
